package com.gzzyy.facerecognition

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.gzzyy.facerecognition.bean.PersonInfo
import com.gzzyy.facerecognition.bean.ResultBean

class ResultFragment(private val personInfo: PersonInfo) : Fragment() {

    private lateinit var adapter: ResultAdapter
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val rootView = inflater.inflate(R.layout.fragment_result, container, false)
        val resultRv = rootView.findViewById<RecyclerView>(R.id.resultRv)
        resultRv.layoutManager = LinearLayoutManager(context)
        Log.e("test","${personInfo}")
        adapter = ResultAdapter()
        resultRv.adapter = adapter
        adapter.setNewData(convertToResultList(personInfo))
        return rootView
    }


    private fun convertToResultList(personInfo: PersonInfo): MutableList<ResultBean> {
        val list = mutableListOf<ResultBean>()
        val attributes = personInfo.attributes
        if(attributes == null){
            list.add(ResultBean("人体朝向：", "未知"))
            list.add(ResultBean("人体是否正常：",  "未知"))
            list.add(ResultBean("是否戴帽：",  "未知"))
            list.add(ResultBean("上身服饰颜色：",  "未知"))
            list.add(ResultBean("是否手提物品：",  "未知"))
            list.add(ResultBean("是否戴口罩：",  "未知"))
            list.add(ResultBean("下身服饰：",  "未知"))
            list.add(ResultBean("是否有交通工具:",  "未知"))
            list.add(ResultBean("上身服饰：",  "未知"))
            list.add(ResultBean("下身服饰颜色：",  "未知"))
            list.add(ResultBean("是否撑伞：",  "未知"))
            list.add(ResultBean("上方是否截断：",  "未知"))
            list.add(ResultBean("下方是否截断：",  "未知"))
            list.add(ResultBean("上身服饰：",  "未知"))
            list.add(ResultBean("性别：",  "未知"))
            list.add(ResultBean("年龄阶段：",  "未知"))
            list.add(ResultBean("是否背包：",  "未知"))
            list.add(ResultBean("是否吸烟：",  "未知"))
            list.add(ResultBean("上身颜色：",  "未知"))
            list.add(ResultBean("是否遮挡：",  "未知"))
            list.add(ResultBean("是否戴眼镜：",  "未知"))
            list.add(ResultBean("是否有手机：",  "未知"))
        }else{
            attributes.let {
                list.add(ResultBean("人体朝向：", it.orientation?.name ?: ""))
                list.add(ResultBean("人体是否正常：", it.is_human?.name ?: ""))
                list.add(ResultBean("是否戴帽：", it.headwear?.name ?: ""))
                list.add(ResultBean("上身服饰颜色：", it.upper_wear_texture?.name ?: ""))
                list.add(ResultBean("是否手提物品：", it.carrying_item?.name ?: ""))
                list.add(ResultBean("是否戴口罩：", it.face_mask?.name ?: ""))
                list.add(ResultBean("下身服饰：", it.lower_wear?.name ?: ""))
                list.add(ResultBean("是否有交通工具:", it.vehicle?.name ?: ""))
                list.add(ResultBean("上身服饰：", it.upper_wear_fg?.name ?: ""))
                list.add(ResultBean("下身服饰颜色：", it.lower_color?.name ?: ""))
                list.add(ResultBean("是否撑伞：", it.umbrella?.name ?: ""))
                list.add(ResultBean("上方是否截断：", it.upper_cut?.name ?: ""))
                list.add(ResultBean("下方是否截断：", it.lower_cut?.name ?: ""))
                list.add(ResultBean("上身服饰：", it.upper_wear?.name ?: ""))
                list.add(ResultBean("性别：", it.gender?.name ?: ""))
                list.add(ResultBean("年龄阶段：", it.age?.name ?: ""))
                list.add(ResultBean("是否背包：", it.bag?.name ?: ""))
                list.add(ResultBean("是否吸烟：", it.smoke?.name ?: ""))
                list.add(ResultBean("上身颜色：", it.upper_color?.name ?: ""))
                list.add(ResultBean("是否遮挡：", it.occlusion?.name ?: ""))
                list.add(ResultBean("是否戴眼镜：", it.glasses?.name ?: ""))
                list.add(ResultBean("是否有手机：", it.cellphone?.name ?: ""))
            }
        }

        return list
    }

}